<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>CSV转SQL工具</title>
    <link th:href="@{/css/bootstrap.min.css}" rel="stylesheet">
    <style>
        .sql-output {
            font-family: monospace;
            white-space: pre-wrap;
            background-color: #f8f9fa;
            padding: 15px;
            border-radius: 5px;
            max-height: 400px;
            overflow-y: auto;
        }
        .btn-copy {
            margin-top: 5px;
            margin-bottom: 15px;
        }
    </style>
</head>
<body>
    <div class="container mt-5">
        <h1 class="mb-4">CSV转SQL工具</h1>
        
        <div class="alert alert-info mb-3">
            <p>本工具用于将配置参数CSV文件转换为SQL语句(DDL和DML)。</p>
            <p>CSV文件格式: Tab分隔的配置参数表，包含id, param_key, param_value等字段。</p>
        </div>
        
        <div th:if="${error}" class="alert alert-danger mb-3" th:text="${error}"></div>
        
        <div class="card mb-4">
            <div class="card-header">
                <h5 class="mb-0">上传CSV文件</h5>
            </div>
            <div class="card-body">
                <form th:action="@{/csv-to-sql/convert}" method="post" enctype="multipart/form-data">
                    <div class="mb-3">
                        <label for="file" class="form-label">选择CSV文件</label>
                        <input class="form-control" type="file" id="file" name="file" accept=".csv">
                    </div>
                    <button type="submit" class="btn btn-primary">转换</button>
                    <a th:href="@{/csv-to-sql/sample}" class="btn btn-outline-secondary">使用示例文件</a>
                </form>
            </div>
        </div>
        
        <div th:if="${ddl}" class="row mb-3">
            <div class="col-12">
                <h4 class="mb-2">生成结果 <small class="text-muted" th:text="${recordCount} + ' 条记录'"></small></h4>
                
                <div class="card mb-4">
                    <div class="card-header">
                        <h5 class="mb-0">DDL - 建表语句</h5>
                    </div>
                    <div class="card-body">
                        <div class="sql-output" id="ddl-content" th:text="${ddl}"></div>
                        <button class="btn btn-sm btn-outline-primary btn-copy" onclick="copyToClipboard('ddl-content')">复制DDL</button>
                    </div>
                </div>
                
                <div class="card mb-4">
                    <div class="card-header">
                        <h5 class="mb-0">DML - 数据插入语句</h5>
                    </div>
                    <div class="card-body">
                        <div class="sql-output" id="dml-content" th:text="${dml}"></div>
                        <button class="btn btn-sm btn-outline-primary btn-copy" onclick="copyToClipboard('dml-content')">复制DML</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
    
    <script>
        function copyToClipboard(elementId) {
            const element = document.getElementById(elementId);
            const text = element.textContent;
            
            navigator.clipboard.writeText(text).then(function() {
                alert('复制成功!');
            }, function() {
                alert('复制失败，请手动复制。');
            });
        }
    </script>
    
    <script th:src="@{/js/bootstrap.bundle.min.js}"></script>
</body>
</html> 